package com.zhaoyu.admin.controller;

import com.zhaoyu.admin.service.WemediaNewsAutoScanService;
import com.zhaoyu.apis.admin.NewsAuthControllerApi;
import com.zhaoyu.common.constants.WemediaConstants;
import com.zhaoyu.model.admin.dtos.NewsAuthDto;
import com.zhaoyu.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news_auth")
public class NewsAuthController implements NewsAuthControllerApi {

    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;

    @Override
    @GetMapping("/autoScanByMediaNewsId/{id}") // rest风格
    public void autoScanByMediaNewsId(@PathVariable("id") Integer id) {
        wemediaNewsAutoScanService.autoScanByMediaNewsId(id);
    }

    @Override
    @PostMapping("/list") // json格式的数据
    public ResponseResult findWmNews(@RequestBody NewsAuthDto newsAuthDto) {
        return wemediaNewsAutoScanService.findWmNews(newsAuthDto);
    }

    @Override
    @GetMapping("/findById/{id}") // rest风格
    public ResponseResult findWmNewsById(@PathVariable("id") Integer id) {
        return wemediaNewsAutoScanService.findWmNewsById(id);
    }

    /**
     * 测试(postman)：
     *      "id": 6164
     *      "type": 1
     */
    @Override
    @PostMapping("/auth_pass") // json格式的数据
    public ResponseResult authPass(@RequestBody NewsAuthDto newsAuthDto) {
        return wemediaNewsAutoScanService.updateStatus(WemediaConstants.PASS,newsAuthDto);
    }

    @Override
    @PostMapping("/auth_fail") // json格式的数据
    public ResponseResult authFail(@RequestBody NewsAuthDto newsAuthDto) {
        return wemediaNewsAutoScanService.updateStatus(WemediaConstants.OVERRULE,newsAuthDto);
    }

}